package com.mo.axion.handler.pending;

import com.mo.axion.common.domain.TaskInfo;
import com.mo.axion.common.pipeline.ProcessContext;
import com.mo.axion.common.pipeline.ProcessController;
import com.mo.axion.common.pipeline.ProcessModel;
import com.mo.axion.common.vo.BasicResultVO;
import com.mo.axion.handler.config.TaskPipelineConfig;
import lombok.Data;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/**
 * @author Mo
 * @createTime 2024/2/17 17:08
 * @description Task 执行器
 */
@Data
@Slf4j
@Component
@Accessors(chain = true)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class Task implements Runnable{
    private TaskInfo taskInfo;

    @Autowired
    @Qualifier("handlerProcessController")
    private ProcessController processController;

    @Override
    public void run() {
        log.info("task:" + Thread.currentThread().getName());
        // TODO 责任链：1. 丢弃消息 2. 屏蔽消息 3. 平台去重 4. 真正发送消息
        ProcessContext<ProcessModel> context =  ProcessContext.builder()
                .processModel(taskInfo)
                .code(TaskPipelineConfig.PIPELINE_HANDLER_CODE)
                .isNeedBreak(false)
                .response(BasicResultVO.success())
                .build();
        processController.process(context);
    }
}
